Random NumbersDirect link to Random Numbers
Generate random numbers using DevAssure's Advanced Code Blocks feature. This is useful for scenarios where you need dynamic numeric data, such as generating random IDs, quantities, or other numerical values during test automation.
Learn more about Advanced Code Blocks
- Getting started: /docs/DevAssure/Code%20Blocks/codeblock/
- Use NPM Libraries in code blocks: /docs/DevAssure/Code%20Blocks/npmLibraries/
Generate a Random Floating-Point Number Between 0 and 1Direct link to Generate a Random Floating-Point Number Between 0 and 1
const randomFloat = Math.random();

Generate a Random Floating-Point Number Between 0 and a Given MaximumDirect link to Generate a Random Floating-Point Number Between 0 and a Given Maximum
const randomFloat = Math.random() * max;

Generate a Random Integer Between 0 and a Given MaximumDirect link to Generate a Random Integer Between 0 and a Given Maximum
const randomInt = Math.floor(Math.random() * (max + 1));

Generate a Random Integer Between Two Values (Inclusive)Direct link to Generate a Random Integer Between Two Values (Inclusive)
min = Math.ceil(min);
max = Math.floor(max);
const randomInt = Math.floor(Math.random() * (max - min + 1)) + min;

Generate a Random Number in a Specific RangeDirect link to Generate a Random Number in a Specific Range
let number = Math.random() * (max - min) + min;

Complete code for random numbersDirect link to Complete code for random numbers

Output for the above codeDirect link to Output for the above code
